import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex)

export default new Vuex.Store({
  //state
  state:{
    totalPrice:0,
    packagePrice:0,
    typeingPrice:0,
    numprice:0
  },
  getters:{
    getPrice(state){
      return state.totalPrice
    }
  },
  mutations:{
    increment(state, currentPrice) {
      state.totalPrice += currentPrice;
    },
    decrement(state, currentPrice) {
      state.totalPrice -= currentPrice;
    },
    fixment(state, currentPrice){
      // totalPrice：最终的值    price     currentPrice：每次变化的值
      state.totalPrice = state.totalPrice - state.numprice + currentPrice;
      state.numprice = currentPrice;
    },
    packaging(state,currentPrice){
      //把上一次的减去   530 = 515  - 15 + 30 = 530
      //  packagePrice = 30   515 = 530 - 30 + 15;
      state.totalPrice = state.totalPrice - state.packagePrice + currentPrice;
      state.packagePrice = currentPrice;
    },
    typeing(state,currentPrice){
      state.totalPrice = state.totalPrice - state.typeingPrice + currentPrice;
      state.typeingPrice = currentPrice;
    }
  },  
  actions:{
    typeings(context,currentPrice){
      setTimeout(function(){
        context.commit("typeing",currentPrice)
      },300)
    }
  }
})
